package com.haixiaoke.saas.manage.department.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HotAttractions;
import com.haixiaoke.saas.house.service.IHotAttractionsService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 热门景点Controller
 *
 * @author xiaolong
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/manage/apartment/attractions")
public class ManageHotAttractionsController extends BaseController {
    @Autowired
    private IHotAttractionsService hotAttractionsService;

    /**
     * 查询热门景点列表
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotAttractions hotAttractions) {
        startPage();
        List<HotAttractions> list = hotAttractionsService.selectHotAttractionsList(hotAttractions);
        return getDataTable(list);
    }

    /**
     * 导出热门景点列表
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotAttractions hotAttractions) {
        List<HotAttractions> list = hotAttractionsService.selectHotAttractionsList(hotAttractions);
        ExcelUtil<HotAttractions> util = new ExcelUtil<HotAttractions>(HotAttractions.class);
        util.exportExcel(response, list, "热门景点数据");
    }

    /**
     * 获取热门景点详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:query')")
    @GetMapping(value = "/{attractionsId}")
    public AjaxResult getInfo(@PathVariable("attractionsId") Long attractionsId) {
        return success(hotAttractionsService.selectHotAttractionsByAttractionsId(attractionsId));
    }

    /**
     * 新增热门景点
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:add')")
    @PostMapping
    public AjaxResult add(@RequestBody HotAttractions hotAttractions) {
        return toAjax(hotAttractionsService.insertHotAttractions(hotAttractions));
    }

    /**
     * 修改热门景点
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody HotAttractions hotAttractions) {
        return toAjax(hotAttractionsService.updateHotAttractions(hotAttractions));
    }

    /**
     * 删除热门景点
     */
//    @PreAuthorize("@ss.hasPermi('business:attractions:remove')")
    @DeleteMapping("/{attractionsIds}")
    public AjaxResult remove(@PathVariable Long[] attractionsIds) {
        return toAjax(hotAttractionsService.deleteHotAttractionsByAttractionsIds(attractionsIds));
    }
}
